/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package processamento;

import java.awt.image.Raster;
import java.awt.image.WritableRaster;
import javax.media.jai.PlanarImage;
import javax.media.jai.TiledImage;

/**
 *
 * @author Igor
 */
public class OperadorBrilho {

     public static PlanarImage alteraBrilho(PlanarImage pi,int qtde) {
            int width = pi.getWidth();
            int height = pi.getHeight();
            int nbands = pi.getNumBands();

            Raster inputRaster = pi.getData();

            WritableRaster outputRaster = inputRaster.createCompatibleWritableRaster();

            int[] pixels = new int[nbands * width * height]; //sempre grayscale

            inputRaster.getPixels(0, 0, width, height, pixels);

            for(int i =0; i < pixels.length; i++)
            {
                pixels[i] = Math.abs(pixels[i]+qtde);

            }

            outputRaster.setPixels(0, 0, width, height, pixels);
            TiledImage ti = new TiledImage(pi, width, height);
            ti.setData(outputRaster);
            return ti;

        }
}
